package com.equipment;

import java.util.Calendar;
import android.annotation.SuppressLint;
import com.util.EncodingUtil;

/**
 * 激活OBU请求幀AB
 *
 * @version 1.18
 * @author 刘亚东
 */
@SuppressLint("DefaultLocale")
public class ActivateOBURequest {

	private String STX = "55AA"; // 帧开始标志
	private String RSCTL = "00"; // 串口帧序列号
	private String Length = ""; // 数据长度
	private String code = "FD"; // 代码
	private String broadening = "AB"; // 扩展代码

	private String BstUnixTime = "";// BST中的Unixtime(4字节)
	private String CurrentDate = "";// 当前时间(4字节)
	private String IsModifySignedDate = "";// 是否修改启用日期1表示修改 0表示不修改 (1字节)
	private String SignedDate = "";// 启用日期(4字节)
	private String IsModifyExpiredDate = "";// 是否修改失效日期1表示修改0表示不修改(1字节)
	private String ExpiredM = "";// 所有截止今日有效期不足M年(1字节)
	private String ExpiredN = "";// 失效日期延期N年(1字节)
	private String IsExpiredN = "";// 启用失效日期延期时延期失效日期，0表示不延期，1表示延期(1字节)

	private String BCC = ""; // 异或校验值

	/**
	 * 发送激活OBU请求幀
	 *
	 * @return
	 */
	public String command(String IsModifySignedDate, String SignedDate,
						  String IsModifyExpiredDate, String ExpiredM, String ExpiredN,
						  String IsExpiredN) {
		this.BstUnixTime = EncodingUtil.LongTosix(
				System.currentTimeMillis() / 1000, 8).toUpperCase();
		this.CurrentDate = EncodingUtil.getTime(Calendar.getInstance());
		this.IsModifySignedDate = EncodingUtil.desToHex(
				Integer.parseInt(IsModifySignedDate), 2);
		// Log.e("IsModifySignedDate",this.IsModifySignedDate);
		this.SignedDate = SignedDate;
		// Log.e("SignedDate",this.SignedDate);
		this.IsModifyExpiredDate = EncodingUtil.desToHex(
				Integer.parseInt(IsModifyExpiredDate), 2);
		// Log.e("IsModifyExpiredDate",this.IsModifyExpiredDate);
		this.ExpiredM = EncodingUtil.desToHex(Integer.parseInt(ExpiredM), 2);
		// Log.e("ExpiredM",this.ExpiredM);
		this.ExpiredN = EncodingUtil.desToHex(Integer.parseInt(ExpiredN), 2);
		// Log.e("ExpiredN",this.ExpiredN);
		this.IsExpiredN = EncodingUtil.plusZero(IsExpiredN, 2);
		// Log.e("IsExpiredN",this.IsExpiredN);
		// 计算出长度转16进制(位数不够补0)
		Length = EncodingUtil.desToHex(
				(broadening + BstUnixTime + this.CurrentDate
						+ this.IsModifySignedDate + this.SignedDate
						+ this.IsModifyExpiredDate + this.ExpiredM
						+ this.ExpiredN + this.IsExpiredN).length() / 2, 4);
		String DATA = RSCTL + Length + code + broadening + BstUnixTime
				+ this.CurrentDate + this.IsModifySignedDate + this.SignedDate
				+ this.IsModifyExpiredDate + this.ExpiredM + this.ExpiredN
				+ this.IsExpiredN;
		// 异或校验从RSCTL到DATA所有字节的异或值
		BCC = EncodingUtil.yihuo(EncodingUtil.change(DATA));
		// 拼接完整的请求
		String retn = STX + DATA + BCC;
		return retn;
	}

	public String getSTX() {
		return STX;
	}

	public void setSTX(String sTX) {
		STX = sTX;
	}

	public String getRSCTL() {
		return RSCTL;
	}

	public void setRSCTL(String rSCTL) {
		RSCTL = rSCTL;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getBroadening() {
		return broadening;
	}

	public void setBroadening(String broadening) {
		this.broadening = broadening;
	}

	public String getBCC() {
		return BCC;
	}

	public void setBCC(String bCC) {
		BCC = bCC;
	}

	public String getLength() {
		return Length;
	}

	public void setLength(String length) {
		Length = length;
	}

	public String getBstUnixTime() {
		return BstUnixTime;
	}

	public void setBstUnixTime(String bstUnixTime) {
		BstUnixTime = bstUnixTime;
	}

	public String getCurrentDate() {
		return CurrentDate;
	}

	public void setCurrentDate(String currentDate) {
		CurrentDate = currentDate;
	}

	public String getIsModifySignedDate() {
		return IsModifySignedDate;
	}

	public void setIsModifySignedDate(String isModifySignedDate) {
		IsModifySignedDate = isModifySignedDate;
	}

	public String getSignedDate() {
		return SignedDate;
	}

	public void setSignedDate(String signedDate) {
		SignedDate = signedDate;
	}

	public String getIsModifyExpiredDate() {
		return IsModifyExpiredDate;
	}

	public void setIsModifyExpiredDate(String isModifyExpiredDate) {
		IsModifyExpiredDate = isModifyExpiredDate;
	}

	public String getExpiredM() {
		return ExpiredM;
	}

	public void setExpiredM(String expiredM) {
		ExpiredM = expiredM;
	}

	public String getExpiredN() {
		return ExpiredN;
	}

	public void setExpiredN(String expiredN) {
		ExpiredN = expiredN;
	}

}
